home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / mac / Chapter Tutorials / CaseStudies / ch14.CSAA / csaaDrive2.dir / 00002_standard routines.ls < prev    next >
Encoding:
Text File  |  1996-08-28  |  3.4 KB  |  147 lines

  1. global gHistory, gBaseURL, gReadyToGo
  2.  
  3. on WaitForTicks theTicks
  4.   set startTime to the timer
  5.   repeat while (startTime + theTicks) > the timer
  6.     nothing()
  7.   end repeat
  8. end
  9.  
  10. on goPage thePage, target
  11.   global gReadyToGo
  12.   recordHistory(thePage)
  13.   if not (thePage contains "/") then
  14.     set thePage to "../" & thePage
  15.   end if
  16.   if gReadyToGo = 1 then
  17.     GoToNetPage(thePage, "csTopicInfo")
  18.     fadeAllSounds(200)
  19.   end if
  20. end
  21.  
  22. on getCurrLabel
  23.   set lastLine to the number of lines in the labelList - 1
  24.   repeat with i = 1 to lastLine
  25.     if the frame < label(line i of the labelList) then
  26.       if i > 1 then
  27.         return line i - 1 of the labelList
  28.       else
  29.         return EMPTY
  30.       end if
  31.       exit
  32.     end if
  33.   end repeat
  34.   return line lastLine of the labelList
  35. end
  36.  
  37. on fadeAllSounds fadeDuration
  38.   if soundBusy(1) or soundBusy(2) then
  39.     set lPlaying to 1
  40.   end if
  41.   if soundBusy(1) then
  42.     sound fadeOut 1, fadeDuration
  43.   end if
  44.   if soundBusy(2) then
  45.     sound fadeOut 2, fadeDuration
  46.   end if
  47.   if lPlaying then
  48.     WaitForTicks(fadeDuration)
  49.   end if
  50. end
  51.  
  52. on recordHistory theURL
  53.   if not gHistory then
  54.     set gHistory to []
  55.   end if
  56.   set index to getPos(gHistory, theURL)
  57.   if index then
  58.     deleteAt(gHistory, index)
  59.   end if
  60.   append(gHistory, theURL)
  61. end
  62.  
  63. on allSprites pup, vis, start, stop
  64.   if not start then
  65.     set start to 1
  66.   end if
  67.   if not stop then
  68.     set stop to 48
  69.   end if
  70.   repeat with i = start to stop
  71.     if not (pup = -1) then
  72.       puppetSprite(i, pup)
  73.     end if
  74.     if not (vis = -1) then
  75.       set the visible of sprite i to vis
  76.     end if
  77.   end repeat
  78. end
  79.  
  80. on distance point1, point2
  81.   set xDiff to the locH of point2 - the locH of point1
  82.   set yDiff to the locV of point2 - the locV of point1
  83.   set dist to sqrt(power(xDiff, 2) + power(yDiff, 2))
  84.   return dist
  85. end
  86.  
  87. on makeTriangle radLength, radLoc, twoPoint
  88.   set thirdPoint to point(the locH of radLoc, the locV of radLoc - radLength)
  89.   set thirdSide to distance(thirdPoint, twoPoint)
  90.   return thirdSide
  91. end
  92.  
  93. on pythagoras radLen, sideLen
  94.   set rvSquare to power(radLen, 2) - power(sideLen, 2)
  95.   return integer(sqrt(rvSquare))
  96. end
  97.  
  98. on radians degrees
  99.   set rVal to degrees * (PI / 180)
  100.   return rVal
  101. end
  102.  
  103. on degrees radians
  104.   set rVal to radians * 180 / PI
  105.   return rVal
  106. end
  107.  
  108. on spriteCenter theSprite
  109.   set rVal to the right of sprite theSprite - integer(the width of sprite theSprite / 2)
  110.   return rVal
  111. end
  112.  
  113. on getFollowAngle theSprite, rxPoint
  114.   global oldMousePoint, oldAngle, oldSprite
  115.   set mousePoint to point(the mouseH, the mouseV)
  116.   if mousePoint <> getaProp(oldMousePoint, theSprite) then
  117.     if not rxPoint then
  118.       set rxPoint to spriteCenter(theSprite)
  119.     end if
  120.     if the mouseH > rxPoint then
  121.       set mult to 1
  122.     else
  123.       set mult to -1
  124.     end if
  125.     set radLength to distance(the loc of sprite theSprite, mousePoint)
  126.     set thirdSide to makeTriangle(radLength, the loc of sprite theSprite, mousePoint) / 2
  127.     set chordLen to pythagoras(radLength, thirdSide)
  128.     setaProp(oldMousePoint, theSprite, mousePoint)
  129.     if chordLen <> 0 then
  130.       set rVal to atan(thirdSide / chordLen) * (360 / PI)
  131.       if not integer(rVal) then
  132.         if string(rVal) contains "-" then
  133.           set rVal to 180
  134.         end if
  135.       else
  136.         set rVal to rVal * mult
  137.       end if
  138.     else
  139.       set rVal to 180
  140.     end if
  141.     setaProp(oldAngle, theSprite, rVal)
  142.   else
  143.     set rVal to getaProp(oldAngle, theSprite)
  144.   end if
  145.   return rVal
  146. end
  147.